﻿Imports System.IO

Public Class Frm_Rech_chohoud

    Private Sub Frm_Rech_chohoud_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_chohoud.Enabled = True
        Frm_Idafa_Chohoud.Enabled = True
    End Sub

    Private Sub Frm_Rech_chohoud_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0
    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            If comb_matorido_elbaht.SelectedItem = "رقم البطاقة الوطنية" Then
                For Each av As Temoins In Partager.moi.List_temoins
                    If av.Cin.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Cin, av.Nom, av.Prenom}))

                    End If

                Next


            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم العائلي" Then

                For Each av As Temoins In Partager.moi.List_temoins
                    If av.Nom.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Cin, av.Nom, av.Prenom}))

                    End If

                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم الشخصي" Then

                For Each av As Temoins In Partager.moi.List_temoins
                    If av.Prenom.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Cin, av.Nom, av.Prenom}))

                    End If

                Next


            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click

        If List_tous.SelectedIndices.Count > 0 Then

            Dim avo As Temoins
            Dim j As Integer = 0
            Try
                For Each i As Integer In List_tous.SelectedIndices
                    avo = Partager.list_recherch(i)
                    If Partager.type = "Ch_Frm_Idafa_Chohoud" Then
                        Frm_Idafa_Chohoud.Comb_chahid.Text = avo.Nom & "  " & avo.Prenom
                    Else
                        For Each khib As Temoins In Partager.moi.List_temoins
                            If avo.Id = khib.Id Then
                                Frm_chohoud.List_tous.Items(j).Focused = True
                                Frm_chohoud.List_tous.Items(j).Selected = True
                            End If
                            j += 1
                        Next
                    End If
                Next
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر شاهد من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub


End Class